GKeyFile *new_config,
GError **error)
{
- gboolean ret = FALSE;
- g_autofree char *data = NULL;
- gsize len;
-
g_return_val_if_fail (self->inited, FALSE);
- data = g_key_file_to_data (new_config, &len, error);
+ gsize len;
+ g_autofree char *data = g_key_file_to_data (new_config, &len, error);
if (!glnx_file_replace_contents_at (self->repo_dir_fd, "config",
(guint8*)data, len, 0,
NULL, error))
- goto out;
+ return FALSE;
g_key_file_free (self->config);
self->config = g_key_file_new ();
if (!g_key_file_load_from_data (self->config, data, len, 0, error))
- goto out;
+ return FALSE;
- ret = TRUE;
- out:
- return ret;
+ return TRUE;
}
/* Bind a subset of an a{sv} to options in a given GKeyfile section */
GCancellable *cancellable,
GError **error)
{
- g_autoptr(OstreeRemote) remote = NULL;
- gboolean different_sysroot = FALSE;
- gboolean ret = FALSE;
-
g_return_val_if_fail (name != NULL, FALSE);
g_return_val_if_fail (url != NULL, FALSE);
g_return_val_if_fail (options == NULL || g_variant_is_of_type (options, G_VARIANT_TYPE ("a{sv}")), FALSE);
if (strchr (name, '/') != NULL)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Invalid character '/' in remote name: %s",
- name);
- goto out;
- }
+ return glnx_throw (error, "Invalid character '/' in remote name: %s", name);
- remote = ost_repo_get_remote (self, name, NULL);
+ g_autoptr(OstreeRemote) remote = ost_repo_get_remote (self, name, NULL);
if (remote != NULL && if_not_exists)
{
- ret = TRUE;
- goto out;
+ /* Note early return */
+ return TRUE;
}
else if (remote != NULL)
{
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Remote configuration for \"%s\" already exists: %s",
- name, remote->file ? gs_file_get_path_cached (remote->file) : "(in config)");
- goto out;
+ return glnx_throw (error,
+ "Remote configuration for \"%s\" already exists: %s",
+ name, remote->file ? gs_file_get_path_cached (remote->file) : "(in config)");
}
remote = ost_remote_new ();
*
* XXX Having API regret about the "sysroot" argument now.
*/
+ gboolean different_sysroot = FALSE;
if (sysroot != NULL)
different_sysroot = !g_file_equal (sysroot, self->sysroot_dir);
if (different_sysroot || ostree_repo_is_system (self))
{
- g_autofree char *basename = g_strconcat (name, ".conf", NULL);
- g_autoptr(GFile) etc_ostree_remotes_d = NULL;
- GError *local_error = NULL;
+ g_autoptr(GError) local_error = NULL;
if (sysroot == NULL)
sysroot = self->sysroot_dir;
- etc_ostree_remotes_d = g_file_resolve_relative_path (sysroot, SYSCONF_REMOTES);
-
+ g_autoptr(GFile) etc_ostree_remotes_d = g_file_resolve_relative_path (sysroot, SYSCONF_REMOTES);
if (!g_file_make_directory_with_parents (etc_ostree_remotes_d,
cancellable, &local_error))
{
}
else
{
- g_propagate_error (error, local_error);
- goto out;
+ g_propagate_error (error, g_steal_pointer (&local_error));
+ return FALSE;
}
}
+ g_autofree char *basename = g_strconcat (name, ".conf", NULL);
remote->file = g_file_get_child (etc_ostree_remotes_d, basename);
}
if (remote->file != NULL)
{
- g_autofree char *data = NULL;
gsize length;
-
- data = g_key_file_to_data (remote->options, &length, NULL);
+ g_autofree char *data = g_key_file_to_data (remote->options, &length, NULL);
if (!g_file_replace_contents (remote->file,
data, length,
NULL, FALSE, 0, NULL,
cancellable, error))
- goto out;
+ return FALSE;
}
else
{
ot_keyfile_copy_group (remote->options, config, remote->group);
if (!ostree_repo_write_config (self, config, error))
- goto out;
+ return FALSE;
}
ost_repo_add_remote (self, remote);
- ret = TRUE;
-
- out:
- return ret;
+ return TRUE;
}
/**
GCancellable *cancellable,
GError **error)
{
- g_autoptr(OstreeRemote) remote = NULL;
- gboolean ret = FALSE;
-
g_return_val_if_fail (name != NULL, FALSE);
if (strchr (name, '/') != NULL)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Invalid character '/' in remote name: %s",
- name);
- goto out;
- }
+ return glnx_throw (error, "Invalid character '/' in remote name: %s", name);
+ g_autoptr(OstreeRemote) remote = NULL;
if (if_exists)
{
remote = ost_repo_get_remote (self, name, NULL);
if (!remote)
{
- ret = TRUE;
- goto out;
+ /* Note early return */
+ return TRUE;
}
}
else
remote = ost_repo_get_remote (self, name, error);
if (remote == NULL)
- goto out;
+ return FALSE;
if (remote->file != NULL)
{
if (unlink (gs_file_get_path_cached (remote->file)) != 0)
- {
- glnx_set_error_from_errno (error);
- goto out;
- }
+ return glnx_throw_errno (error);
}
else
{
- g_autoptr(GKeyFile) config = NULL;
-
- config = ostree_repo_copy_config (self);
+ g_autoptr(GKeyFile) config = ostree_repo_copy_config (self);
/* XXX Not sure it's worth failing if the group to remove
* isn't found. It's the end result we want, after all. */
if (g_key_file_remove_group (config, remote->group, NULL))
{
if (!ostree_repo_write_config (self, config, error))
- goto out;
+ return FALSE;
}
}
/* Delete the remote's keyring file, if it exists. */
if (!ot_ensure_unlinked_at (self->repo_dir_fd, remote->keyring, error))
- goto out;
+ return FALSE;
ost_repo_remove_remote (self, remote);
- ret = TRUE;
-
- out:
- return ret;
+ return TRUE;
}
/**
char **out_url,
GError **error)
{
- g_autofree char *url = NULL;
- gboolean ret = FALSE;
-
g_return_val_if_fail (name != NULL, FALSE);
+ g_autofree char *url = NULL;
if (_ostree_repo_remote_name_is_file (name))
{
url = g_strdup (name);
else
{
if (!ostree_repo_get_remote_option (self, name, "url", NULL, &url, error))
- goto out;
+ return FALSE;
if (url == NULL)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
"No \"url\" option in remote \"%s\"", name);
- goto out;
+ return FALSE;
}
}
if (out_url != NULL)
*out_url = g_steal_pointer (&url);
-
- ret = TRUE;
-
- out:
- return ret;
+ return TRUE;
}
/**
const char **out_mode,
GError **error)
{
- gboolean ret = FALSE;
const char *ret_mode;
switch (mode)
ret_mode ="archive-z2";
break;
default:
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Invalid mode '%d'", mode);
- goto out;
+ return glnx_throw (error, "Invalid mode '%d'", mode);
}
- ret = TRUE;
*out_mode = ret_mode;
- out:
- return ret;
+ return TRUE;
}
gboolean
OstreeRepoMode *out_mode,
GError **error)
{
- gboolean ret = FALSE;
OstreeRepoMode ret_mode;
if (strcmp (mode, "bare") == 0)
strcmp (mode, "archive") == 0)
ret_mode = OSTREE_REPO_MODE_ARCHIVE_Z2;
else
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Invalid mode '%s' in repository configuration", mode);
- goto out;
- }
+ return glnx_throw (error, "Invalid mode '%s' in repository configuration", mode);
- ret = TRUE;
*out_mode = ret_mode;
- out:
- return ret;
+ return TRUE;
}
#define DEFAULT_CONFIG_CONTENTS ("[core]\n" \
{
if (errno == ENOENT)
{
- const char *mode_str;
+ const char *mode_str = NULL;
g_autoptr(GString) config_data = g_string_new (DEFAULT_CONFIG_CONTENTS);
if (!ostree_repo_mode_to_string (mode, &mode_str, error))
return FALSE;
+ g_assert (mode_str);
g_string_append_printf (config_data, "mode=%s\n", mode_str);
GCancellable *cancellable,
GError **error)
{
- gboolean ret = FALSE;
- GError *temp_error = NULL;
+ g_autoptr(GError) temp_error = NULL;
g_autoptr(GFileEnumerator) ret_direnum = NULL;
ret_direnum = g_file_enumerate_children (dirpath, queryargs, queryflags,
if (!ret_direnum)
{
if (g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
+ g_clear_error (&temp_error);
+ else
{
- g_clear_error (&temp_error);
- ret = TRUE;
+ g_propagate_error (error, g_steal_pointer (&temp_error));
+ return FALSE;
}
- else
- g_propagate_error (error, temp_error);
-
- goto out;
}
- ret = TRUE;
if (out_direnum)
*out_direnum = g_steal_pointer (&ret_direnum);
- out:
- return ret;
+ return TRUE;
}
static gboolean
GCancellable *cancellable,
GError **error)
{
- gboolean ret = FALSE;
g_autoptr(GKeyFile) remotedata = g_key_file_new ();
-
if (!g_key_file_load_from_file (remotedata, gs_file_get_path_cached (path),
0, error))
- goto out;
-
- ret = add_remotes_from_keyfile (self, remotedata, path, error);
+ return FALSE;
- out:
- return ret;
+ return add_remotes_from_keyfile (self, remotedata, path, error);
}
static GFile *
return FALSE;
if (strcmp (version, "1") != 0)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Invalid repository version '%s'", version);
- return FALSE;
- }
+ return glnx_throw (error, "Invalid repository version '%s'", version);
if (!ot_keyfile_get_boolean_with_default (self->config, "core", "archive",
FALSE, &is_archive, error))
GCancellable *cancellable,
GError **error)
{
- gboolean ret = FALSE;
- g_autoptr(GFile) remotes_d = NULL;
- g_autoptr(GFileEnumerator) direnum = NULL;
g_mutex_lock (&self->remotes_lock);
g_hash_table_remove_all (self->remotes);
g_mutex_unlock (&self->remotes_lock);
if (!add_remotes_from_keyfile (self, self->config, NULL, error))
- goto out;
+ return FALSE;
- remotes_d = get_remotes_d_dir (self);
+ g_autoptr(GFile) remotes_d = get_remotes_d_dir (self);
if (remotes_d == NULL)
return TRUE;
+ g_autoptr(GFileEnumerator) direnum = NULL;
if (!enumerate_directory_allow_noent (remotes_d, OSTREE_GIO_FAST_QUERYINFO, 0,
&direnum,
cancellable, error))
- goto out;
+ return FALSE;
if (direnum)
{
while (TRUE)
if (!g_file_enumerator_iterate (direnum, &file_info, &path,
NULL, error))
- goto out;
+ return FALSE;
if (file_info == NULL)
break;
g_str_has_suffix (name, ".conf"))
{
if (!append_one_remote_config (self, path, cancellable, error))
- goto out;
+ return FALSE;
}
}
}
- ret = TRUE;
- out:
- return ret;
+ return TRUE;
}
/**
GCancellable *cancellable,
GError **error)
{
- gboolean ret = FALSE;
struct stat stbuf;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
&boot_id,
NULL,
error))
- goto out;
+ return FALSE;
g_strdelimit (boot_id, "\n", '\0');
}
&self->repo_dir_fd, error))
{
g_prefix_error (error, "%s: ", gs_file_get_path_cached (self->repodir));
- goto out;
+ return FALSE;
}
if (!glnx_opendirat (self->repo_dir_fd, "objects", TRUE,
&self->objects_dir_fd, error))
{
g_prefix_error (error, "Opening objects/ directory: ");
- goto out;
+ return FALSE;
}
self->writable = faccessat (self->objects_dir_fd, ".", W_OK, 0) == 0;
{
/* This is returned through ostree_repo_is_writable(). */
glnx_set_error_from_errno (&self->writable_error);
+ /* Note - we don't return this error yet! */
}
if (fstat (self->objects_dir_fd, &stbuf) != 0)
- {
- glnx_set_error_from_errno (error);
- goto out;
- }
+ return glnx_throw_errno (error);
if (stbuf.st_uid != getuid () || stbuf.st_gid != getgid ())
{
}
if (!glnx_opendirat (self->repo_dir_fd, "tmp", TRUE, &self->tmp_dir_fd, error))
- goto out;
+ return FALSE;
if (self->writable)
{
if (!glnx_shutil_mkdir_p_at (self->tmp_dir_fd, _OSTREE_CACHE_DIR, 0775, cancellable, error))
- goto out;
+ return FALSE;
if (!glnx_opendirat (self->tmp_dir_fd, _OSTREE_CACHE_DIR, TRUE, &self->cache_dir_fd, error))
- goto out;
+ return FALSE;
}
if (!ostree_repo_reload_config (self, cancellable, error))
- goto out;
+ return FALSE;
/* TODO - delete this */
if (self->mode == OSTREE_REPO_MODE_ARCHIVE_Z2 && self->enable_uncompressed_cache)
{
if (!glnx_shutil_mkdir_p_at (self->repo_dir_fd, "uncompressed-objects-cache", 0755,
cancellable, error))
- goto out;
+ return FALSE;
if (!glnx_opendirat (self->repo_dir_fd, "uncompressed-objects-cache", TRUE,
&self->uncompressed_objects_dir_fd,
error))
- goto out;
+ return FALSE;
}
self->inited = TRUE;
-
- ret = TRUE;
- out:
- return ret;
+ return TRUE;
}
/**
/* Replace the contents of a file, honoring the repository's fsync
* policy.
- */
-gboolean
+ */
+gboolean
_ostree_repo_file_replace_contents (OstreeRepo *self,
int dfd,
const char *path,
GCancellable *cancellable,
GError **error)
{
- gboolean ret = FALSE;
guint c;
int dfd = -1;
static const gchar hexchars[] = "0123456789abcdef";
if (errno == ENOENT)
continue;
else
- {
- glnx_set_error_from_errno (error);
- goto out;
- }
+ return glnx_throw_errno (error);
}
/* Takes ownership of dfd */
if (!list_loose_objects_at (self, inout_objects, buf, dfd,
commit_starting_with,
cancellable, error))
- goto out;
+ return FALSE;
}
- ret = TRUE;
- out:
- return ret;
+ return TRUE;
}
static gboolean
GCancellable *cancellable,
GError **error)
{
- gboolean ret = FALSE;
char loose_path_buf[_OSTREE_LOOSE_PATH_MAX];
struct stat stbuf;
glnx_fd_close int fd = -1;
if (!ot_openat_ignore_enoent (self->objects_dir_fd, loose_path_buf, &fd,
error))
- goto out;
+ return FALSE;
if (fd < 0 && self->commit_stagedir_fd != -1)
{
if (!ot_openat_ignore_enoent (self->commit_stagedir_fd, loose_path_buf, &fd,
error))
- goto out;
+ return FALSE;
}
if (fd != -1)
{
if (fstat (fd, &stbuf) < 0)
- {
- glnx_set_error_from_errno (error);
- goto out;
- }
+ return glnx_throw_errno (error);
if (out_variant)
{
mfile = g_mapped_file_new_from_fd (fd, FALSE, error);
if (!mfile)
- goto out;
+ return FALSE;
ret_variant = g_variant_new_from_data (ostree_metadata_variant_type (objtype),
g_mapped_file_get_contents (mfile),
g_mapped_file_get_length (mfile),
{
g_autoptr(GBytes) data = glnx_fd_readall_bytes (fd, cancellable, error);
if (!data)
- goto out;
+ return FALSE;
ret_variant = g_variant_new_from_bytes (ostree_metadata_variant_type (objtype),
data, TRUE);
g_variant_ref_sink (ret_variant);
{
ret_stream = g_unix_input_stream_new (fd, TRUE);
if (!ret_stream)
- goto out;
+ return FALSE;
fd = -1; /* Transfer ownership */
}
else if (self->parent_repo)
{
if (!ostree_repo_load_variant (self->parent_repo, objtype, sha256, &ret_variant, error))
- goto out;
+ return FALSE;
}
else if (error_if_not_found)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
"No such metadata object %s.%s",
sha256, ostree_object_type_to_string (objtype));
- goto out;
+ return FALSE;
}
- ret = TRUE;
ot_transfer_out_value (out_variant, &ret_variant);
ot_transfer_out_value (out_stream, &ret_stream);
- out:
- return ret;
+ return TRUE;
}
static gboolean
GCancellable *cancellable,
GError **error)
{
- gboolean ret = FALSE;
char loose_path[_OSTREE_LOOSE_PATH_MAX];
int res;
struct stat stbuf;
_ostree_loose_path (loose_path, sha256, objtype, self->mode);
- do
+ do
res = fstatat (self->objects_dir_fd, loose_path, &stbuf, AT_SYMLINK_NOFOLLOW);
while (G_UNLIKELY (res == -1 && errno == EINTR));
if (G_UNLIKELY (res == -1))
- {
- glnx_set_prefix_error_from_errno (error, "Querying object %s.%s", sha256, ostree_object_type_to_string (objtype));
- goto out;
- }
+ return glnx_throw_errno_prefix (error, "Querying object %s.%s", sha256, ostree_object_type_to_string (objtype));
*out_size = stbuf.st_size;
- ret = TRUE;
- out:
- return ret;
+ return TRUE;
}
/**
OstreeRepoCommitState *out_state,
GError **error)
{
- gboolean ret = FALSE;
-
if (out_variant)
{
if (!load_metadata_internal (self, OSTREE_OBJECT_TYPE_COMMIT, checksum, TRUE,
out_variant, NULL, NULL, NULL, error))
- goto out;
+ return FALSE;
}
if (out_state)
}
else if (errno != ENOENT)
{
- glnx_set_error_from_errno (error);
- goto out;
+ return glnx_throw_errno (error);
}
}
- ret = TRUE;
- out:
- return ret;
+ return TRUE;
}
/**
GCancellable *cancellable,
GError **error)
{
- gboolean ret = FALSE;
- g_autoptr(GHashTable) ret_objects = NULL;
-
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
g_return_val_if_fail (self->inited, FALSE);
- ret_objects = g_hash_table_new_full (ostree_hash_object_name, g_variant_equal,
- (GDestroyNotify) g_variant_unref,
- (GDestroyNotify) g_variant_unref);
+ g_autoptr(GHashTable) ret_objects =
+ g_hash_table_new_full (ostree_hash_object_name, g_variant_equal,
+ (GDestroyNotify) g_variant_unref,
+ (GDestroyNotify) g_variant_unref);
if (flags & OSTREE_REPO_LIST_OBJECTS_ALL)
flags |= (OSTREE_REPO_LIST_OBJECTS_LOOSE | OSTREE_REPO_LIST_OBJECTS_PACKED);
if (flags & OSTREE_REPO_LIST_OBJECTS_LOOSE)
{
if (!list_loose_objects (self, ret_objects, NULL, cancellable, error))
- goto out;
+ return FALSE;
if ((flags & OSTREE_REPO_LIST_OBJECTS_NO_PARENTS) == 0 && self->parent_repo)
{
if (!list_loose_objects (self->parent_repo, ret_objects, NULL, cancellable, error))
- goto out;
+ return FALSE;
}
}
/* Nothing for now... */
}
- ret = TRUE;
ot_transfer_out_value (out_objects, &ret_objects);
- out:
- return ret;
+ return TRUE;
}
/**
GCancellable *cancellable,
GError **error)
{
- gboolean ret = FALSE;
- g_autoptr(GFile) ret_root = NULL;
g_autofree char *resolved_commit = NULL;
-
if (!ostree_repo_resolve_rev (self, ref, FALSE, &resolved_commit, error))
- goto out;
+ return FALSE;
- ret_root = (GFile*) _ostree_repo_file_new_for_commit (self, resolved_commit, error);
+ g_autoptr(GFile) ret_root = (GFile*) _ostree_repo_file_new_for_commit (self, resolved_commit, error);
if (!ret_root)
- goto out;
+ return FALSE;
if (!ostree_repo_file_ensure_resolved ((OstreeRepoFile*)ret_root, error))
- goto out;
+ return FALSE;
- ret = TRUE;
ot_transfer_out_value(out_root, &ret_root);
ot_transfer_out_value(out_commit, &resolved_commit);
- out:
- return ret;
+ return TRUE;
}
/**
gboolean *out_did_lock,
GError **error)
{
- gboolean ret = FALSE;
g_autofree char *lock_name = g_strconcat (tmpdir_name, "-lock", NULL);
gboolean did_lock = FALSE;
g_autoptr(GError) local_error = NULL;
else
{
g_propagate_error (error, g_steal_pointer (&local_error));
- goto out;
+ return FALSE;
}
}
else
did_lock = TRUE;
}
- ret = TRUE;
*out_did_lock = did_lock;
- out:
- return ret;
+ return TRUE;
}
/* This allocates and locks a subdir of the repo tmp dir, using an existing